package com.junzhiit.nengji.shop.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.shop.service.GoodsService;
import com.junzhiit.nengji.shop.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/goods")
public class GoodsController extends BaseController {

	@Autowired
	private GoodsService goodsService;
	
	@ApiOperation(value = "根据商品名称查询商品")
	@RequestMapping(value = "/search",method = RequestMethod.GET)
	public ResultVO findAllByType(String name,String typeId,String userId,String shopId,Integer status){
		AssertUtil.notBlank(shopId, "shopId is required.");
		return goodsService.findGoods(name, typeId,userId,shopId,status);
	}
	
	@ApiOperation(value = "根据code查询商品详情(带五星好评、优惠劵)")
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public ResultVO findGoodsInfoNew(String code,String userId) {
		AssertUtil.notBlank(code, "code is required.");
		return goodsService.findGoodsInfoNew(code,userId);
	}
	
	@ApiOperation(value = "检验商品库存")
	@RequestMapping(value = "/check/stock", method = RequestMethod.GET)
	public ResultVO checkStock(String goodsInfo) {
		return goodsService.checkStock(goodsInfo);
	}
}
